<?php
require('includes/top.php');

$desn = $_POST['desn'];

$userid = $_POST['userid'];
$division = $_POST['division'];
$region = $_POST['region'];
$modelname_array = explode('-',$_POST['laptop_model']);
$laptop_modelname = $modelname_array[1];
$serial_no = $modelname_array[2];
/*if($desn="MT")
{
$laptop_model = $_POST['laptop_model1'];
}
else
{
$laptop_model = $_POST['laptop_model'];
}*/

$depot_location = $_POST['depot_location'];
$dispatch_location = $_POST['dispatch_location'];
$dispatch_date = $_POST['dispatch_date'];
$dispatch_location_address = $_POST["dispatch_location_address"];
$date = date("d-m-y");


//$modelname_array = explode('-',$laptop_model);
$sql8 = "select laptop_id from laptop_details where laptop_name='".trim($modelname_array[0])."' and laptop_model='".trim($modelname_array[1])."' and serial_no='".trim($modelname_array[2])."' and status!=0";
$result8 = mysql_query($sql8);
while($row8 = mysql_fetch_row($result8))
{
$minid .= $row8[0];
}

$sql10 = "select serial_no from laptop_details where laptop_id='".trim($minid)."'";
$result10 = mysql_query($sql10);
$row10 = mysql_fetch_row($result10);
$serial_no = $row10[0];

$sql9="UPDATE laptop_details SET `status` = '0' WHERE laptop_id = '".trim($minid)."'";
$result9=mysql_query($sql9);

$sql1="INSERT INTO laptop(`laptop_id`,`user_id`,`division`,`region`,`laptopmodel`,`depot_location`,`dispatch_location`,`dispatch_date`,`serial_no`,`date`,`user_name`,`dispatch_location_add`) VALUES ('".trim($minid)."','$user_id','$division','$region','".trim($modelname_array[1])."','$depot_location','$dispatch_location','$dispatch_date','$serial_no','$date','".$_SESSION['user_name']."','$dispatch_location_address')";
$result1=mysql_query($sql1);



$sql2="Delete from pending_request where user_id='".trim($userid)."'";
$result2=mysql_query($sql2);

if($result1>0)
{
header('Location:pending_request.php?v=success');
}
else
{
header('Location:pending_request.php?v=err');
}
?>